#include "junix.h"

#include <boost/mem_fn.hpp>

using namespace std;

struct A
{
	int i;
	A(int n=0):i(n){ }

	void print(){ cout<<i<<" "; }
	void plus1(){i++;}
	static void hello()
	{
		std::cout<<"I am class A"<<std::endl;
	}
};

void print_hello()
{
	printf("hello world!\n");
}

int main(int argc, char **argv)
{
	vector<A> vA;
	for(int i=0;i<20;i++)
	{
		vA.push_back(A(i));
	}

	for_each(vA.begin(),vA.end(),
			mem_fun_ref(&A::print) );
	cout<<endl;

	for_each(vA.begin(),vA.end(),
			mem_fun_ref(&A::plus1));
	for_each(vA.begin(),vA.end(),
			mem_fun_ref(&A::print));
	cout<<endl;

	for_each(vA.begin(),vA.end(),
			boost::mem_fn(&A::plus1));
	for_each(vA.begin(),vA.end(),
			boost::mem_fn(&A::print));
	cout<<endl;

	for_each(vA.begin(),vA.end(),
			boost::bind(&A::plus1,_1));
	for_each(vA.begin(),vA.end(),
			boost::bind(&A::print, _1));
	cout<<endl;


	for_each(vA.begin(), vA.end(),
			boost::bind(A::hello));

	for_each(vA.begin(), vA.end(),
			boost::bind(print_hello));
}
